package com.aditya.testmvcapp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aditya.testmvcapp.domain.PriceIncrease;
import com.aditya.testmvcapp.domain.Product;
import com.aditya.testmvcapp.persistence.ApplicationDao;

@Component
public class PriceIncreaseService {

	@Autowired
	private ApplicationDao applicationDao;

	public void increasePrice(PriceIncrease priceIncrease) {
		Product product = applicationDao.getProduct(priceIncrease
				.getDescription());
		double price = product.getPrice();
		product.setPrice(price
				+ ((priceIncrease.getPercentage() / 100) * price));
		
		applicationDao.updateProduct(product);
	}

	public ApplicationDao getApplicationDao() {
		return applicationDao;
	}

	public void setApplicationDao(ApplicationDao applicationDao) {
		this.applicationDao = applicationDao;
	}
}
